package tictactoe;


import java.util.Scanner;
// program to test the GameLogic class

public class tictactoe {
   public static void main(String args[]) {
	   GameLogic g = new GameLogic(4); // create a 4x4 bard
	   //g.setThreats(true); // show when players can win in 1 move
	   while(true) {
		   // loop while the game isn't over
		   int w,x,y,z;
		   Scanner in = new Scanner(System.in);
		   System.out.print("Enter command number\n"); 
		   int command = in.nextInt();
		   System.out.print(command);
		   if(command == 1) {
			   System.out.print("undo\n");
			   g.undo();
		   }
		   else if (command == 2) {
			   System.out.print("redo\n");
			   g.redo();
		   }
		   else {
		   
			   System.out.printf("Please enter w coordinate\n");
			   w = in.nextInt();
			   System.out.printf("Please enter x coordinate\n");
			   x = in.nextInt();
			   System.out.printf("Please enter y coordinate\n");
			   y = in.nextInt();
			   System.out.printf("Please enter z coordinate\n");
			   z = in.nextInt();
			   g.makeMove(w, x, y, z);
			   if(g.winState() == GameStatus.Draw) {
				   System.out.printf("it's a draw\n");
				   break;
			   }
			   if(g.winState() == GameStatus.Xwin) {
				   System.out.printf("player 1 wins\n");
				   break;
			   }
			   if(g.winState() == GameStatus.Owin) {
				   System.out.printf("player 2 wins\n");
				   break;
			   }
		   }
		   print(g);
	   }
	   print(g);

   }
   
   public static void print(GameLogic g) {
	   //Prints the board
	   SquareColor[][][][] board = g.gameState();
	   int length = g.getLength();
	   for(int coord2 = 0; coord2 < length; coord2++) {
		   for(int coord4 = 0; coord4 < length; coord4++) {
			   for(int coord1 = 0; coord1 < length; coord1++) {
				   for(int coord3 = 0; coord3 < length; coord3++) {
					   printSquare(board[coord1][coord2][coord3][coord4]);
					   if(coord3 != length - 1) {
						   System.out.printf("|");
					   }
				   }
				   System.out.print("  ");
			   }
			   System.out.println();
			   if(coord4 != length-1) {
				   for(int coord1 = 0; coord1 < length; coord1++) {
					   for(int coord3 = 0; coord3 < length; coord3++) {
						   System.out.printf("_");
						   if(coord3 != length - 1) {
							   System.out.printf(".");
						   }
					   }
				/*	   if(coord1 != length - 1) {
						   System.out.printf(" ");
					   }*/
					   System.out.print("  ");
				   }
			   }
			   System.out.println();
		   }
		   System.out.println();
	   }
   }   


   public static void printSquare(SquareColor square) {
	   if(square == SquareColor.X) {
		   System.out.print('X');
	   }
	   if(square == SquareColor.O) {
		   System.out.print('O');
	   }
	   if(square == SquareColor.Xthreat) {
		   System.out.print('*');
	   }
	   if(square == SquareColor.Othreat) {
		   System.out.print('+');
	   }
	   if(square == SquareColor.Empty) {
		   System.out.print(" ");
	   }
   }
}